#SIMPLE NGINX SERVER with AUTHENTICATION
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |
    user nginx;
    worker_processes  2;
    error_log  /var/log/nginx/error.log;
    events {
      worker_connections  10240;
    }
    http {
      
      server {
          listen       80;
          server_name  localhost;
          location / {
              root   /usr/share/nginx/html;
              index  index.html index.htm;
          }
          auth_basic "Secure Site";
          auth_basic_user_file conf/htpasswd;
        }
    }

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-htpasswd
data:
  htpasswd: |
    root:$apr1$91kF9CbQ$yqJvNIZkWMMXM6h/6RVZJ0  
# echo password | openssl passwd -apr1 -stdin

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx      
    spec:
      containers:
      - name: nginx
        image: nginx:1.24.0
        resources:
          limits:
            memory: "1Gi"
            cpu: "1000m"
          requests:
            memory: "500Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-volume
          mountPath: /etc/nginx # mount nginx-conf volume to /etc/nginx
        - name: nginx-htpasswd
          mountPath: /etc/nginx/conf #mount htpasswd volume to /etc/nginc/conf
      volumes:
      - name: nginx-volume
        configMap:
          name: nginx-conf # place ConfigMap `nginx-conf` on /etc/nginx
      - name: nginx-htpasswd
        configMap: 
          name: nginx-htpasswd      

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30001
  selector:
    app: nginx




